/*
 * ESTO ES UNA LICENCIA DE PRUEBA
 * EL CODIGO ES DE LIBRE ACCESO PERO ACUERDESE QUE ESTA BAJO LICENCIA
 */
package org.japo.java.matisse.samples;

import java.awt.Color;
import java.awt.Container;

/**
 *
 * @author (c) 2014 - TUTORIALES DE NETBEANS Y JAVA
 */
public class TextoAsistido extends javax.swing.JFrame {

    /**
     * Creates new form TextoAsistido
     */
    public TextoAsistido() {
        iniciarAnterior();
        initComponents();
        iniciarPosterior();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnlPrincipal = new javax.swing.JPanel();
        txfTexto = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("CambioColor");

        txfTexto.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txfTexto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txfTextoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlPrincipalLayout = new javax.swing.GroupLayout(pnlPrincipal);
        pnlPrincipal.setLayout(pnlPrincipalLayout);
        pnlPrincipalLayout.setHorizontalGroup(
            pnlPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlPrincipalLayout.createSequentialGroup()
                .addContainerGap(181, Short.MAX_VALUE)
                .addComponent(txfTexto, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(180, 180, 180))
        );
        pnlPrincipalLayout.setVerticalGroup(
            pnlPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlPrincipalLayout.createSequentialGroup()
                .addGap(137, 137, 137)
                .addComponent(txfTexto, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(166, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pnlPrincipal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pnlPrincipal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        setSize(new java.awt.Dimension(481, 370));
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void txfTextoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txfTextoActionPerformed
        cambiarColor();
    }//GEN-LAST:event_txfTextoActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TextoAsistido.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TextoAsistido.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TextoAsistido.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TextoAsistido.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new TextoAsistido().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel pnlPrincipal;
    private javax.swing.JTextField txfTexto;
    // End of variables declaration//GEN-END:variables

    //Antes de la creacion del interfaz
    private void iniciarAnterior() {
       
    }

//    Despues de la creacion del interfaz, pero antes de que se vea
    private void iniciarPosterior() {
        
    }

    private void cambiarColor() {
         

        String texto = txfTexto.getText().toUpperCase();

        //Acceder al panel contenedor
        
        Container pnlPrincipal = this.getContentPane();
        
        //Analiza el texto
        switch (texto) {
            case "ROJO":
                pnlPrincipal.setBackground(Color.RED);
                break;
            case "AZUL":
                pnlPrincipal.setBackground(Color.BLUE);
                break;
            case "VERDE":
                pnlPrincipal.setBackground(Color.GREEN);
                break;
            case "AMARILLO":
                pnlPrincipal.setBackground(Color.YELLOW);
                break;
            case "NARANJA":
                pnlPrincipal.setBackground(Color.ORANGE);
                break;
            case "ROSA":
                pnlPrincipal.setBackground(Color.PINK);
                break;
            case "NEGRO":
                pnlPrincipal.setBackground(Color.BLACK);
                break;
                 case "GRIS":
                pnlPrincipal.setBackground(Color.LIGHT_GRAY);
               
                break;
            default:
                
pnlPrincipal.setBackground(new Color(240,240, 240));
        }
    }
}
